# pip install zhipuai 请先在终端进行安装

import zhipuai

zhipuai.api_key = "41805a5412196acfdd9d63a905f9039a.Z0TWy2173NoP1ZkI"
response = zhipuai.model_api.sse_invoke(
    model="chatglm_std",
    prompt= [{"role":"user","content":"请以“丰富多彩的大学生活“为微电影主题，创作一篇微电影创意脚本(片长为3分钟)，并遵循以下要求：\n1、先写故事梗概，再按场景写脚本。\n2、分镜头运用必须流畅自然。\n3、画面形象须简捷易懂。\n4、分镜头间的连接须明确。\n5、对话，音效等标识需明确。"}],
    temperature= 0.9,
    top_p= 0.7,
    incremental=True
)

for event in response.events():
    if event.event == "add":
        print(event.data, end="")
    elif event.event == "error" or event.event == "interrupted":
        print(event.data, end="")
    elif event.event == "finish":
        print(event.data)
        print(event.meta, end="")
    else:
        print(event.data, end="")